<template>
	<!--父级调用 FlowNodeTmp -->
	<div>
		<a-form
			ref="searchRef"
			layout="inline"
			:model="flowSearch"
			:label-col="labelCol"
			@finish="loading=true;"
		>
			<!-- <a-form-item label="审核角色">
				<a-select
					v-model:value="flowSearch.role_id"
					allow-clear
					style="width: 120px"
					@change="changeflowStatus"
				>
					<a-select-option
						v-for="item in roles"
						:key="item.id"
						:value="item.id"
					>{{ item.name }}</a-select-option>
				</a-select>
			</a-form-item> -->
			<a-form-item label="审核状态">
				<a-select
					v-model:value="flowSearch.status"
					allow-clear
					style="width: 120px"
					@change="changeflowStatus"
				>
					<a-select-option value="-1">已退回</a-select-option>
					<a-select-option value="0">待审核</a-select-option>
					<a-select-option value="1">已审核</a-select-option>
					<a-select-option value="2">已完成</a-select-option>
				</a-select>
			</a-form-item>
		</a-form>
	</div>
</template>
<script setup>
/**
 * 项目进度节点状态按钮
 */
import { ref, onMounted } from "vue";
const flowStatus = ref();
flowStatus.value = [
	{ status: -1, name: "已退回" },
	{ status: 0, name: "待审核" },
	{ status: 1, name: "已通过" },
	{ status: 2, name: "完成" },
];
const getStatusTab = (status) => {
	var data = flowStatus.value.find((e) => {
		if (e.status === status) {
			return e;
		}
	});
	if (data) {
		return data.name;
	}
	return "";
};
import { useRoute } from "vue-router";
// const { proxy } = getCurrentInstance();

import { post, treeToList } from "../utils";
const route = useRoute();
// console.log(route.name);
const flowSearch = ref({});
const searchState = ref({});
// flowSearch.value = route.query;
const openStart = ref(0);
//定义emit
const emit = defineEmits(["change"]);
const initData = () => {
	emit("change", { ids: searchState.value.ids });
};
// defineExpose({initData})
const roles = ref();
const getFlowType = () => {
	var moduleId = flowSearch.value.module_id;
	if (moduleId) {
		post("flow/getFlowType", {
			module_id: moduleId,
		}).then(({ data }) => {
			// console.log(data);
			if (data) {
				roles.value = data.roles;
			}
			// searchState.value.ids = res.data.join(",");
		});
	}
};
const getStatusIds = () => {
	post("flow/getItemIds", {
		...flowSearch.value,
	}).then((res) => {
		searchState.value.ids = res.data.join(",");
		initData();
	});
};
const changeflowStatus = (e) => {
	if (!searchState.value) {
		return;
	}
	if (e === undefined) {
		searchState.value.ids = "";
		initData();
	} else {
		getStatusIds();
	}
};
onMounted(() => {
	flowSearch.value.module_id =
		route.query.flow_module_id || props.moduleId || route.name || "";
	flowSearch.value.status = route.query.flow_status || props.status || "";
	flowSearch.value.role_id = route.query.flow_role_id || "";
	getFlowType();
	if (flowSearch.value.status && flowSearch.value.module_id) {
		getStatusIds();
	} else {
		initData();
	}
});
const props = defineProps({
	moduleId: {
		type: String,
		required: true,
		default: "",
	},
	labelCol: {
		type: Object,
		required: false,
	}
});
</script>
